<template>
  <div class="app-container">
    <!-- <strong>讲师列表</strong> -->
    <!--学院查询表单-->
    <div style="display: flex; justify-content: space-between;">

      <!--学院查询表单-->
      <el-card class="box-card" style="flex: 1; height: 590px; overflow-y: auto; margin-right: 10px;">
        <div slot="header" class="clearfix">
          <span><strong>学院</strong></span>
          <el-button style="float: right; padding: 3px 0" type="text" @click="categoryAdd">添加学院</el-button>
        </div>
        <div v-for="(o, index) in category" :key="o.id" class="text item">
          {{ index + 1 }}. {{ o.college }}
          <el-button style="float: right; padding: 3px 0" type="text" @click="categoryDeleteById(o.id)">删除</el-button>
        </div>
      </el-card>

      <!--教师提交材料-->
      <el-card class="box-card" style="flex: 1; height: 590px; overflow-y: auto;margin-left: 10px;">
        <div slot="header" class="clearfix">
          <span><strong>提交材料类别</strong></span>
          <el-button style="float: right; padding: 3px 0" type="text" @click="busAdd">添加分类</el-button>
        </div>
        <div v-for="(o, index) in bus" :key="o.id" class="text item">
          {{ index + 1 }}. {{ o.title }} ..........{{"绩效：" + o.count }}
          <el-button style="float: right; padding: 3px 0" type="text" @click="busDeleteById(o.id)">删除</el-button>
        </div>
      </el-card>

      <!--项目申报类别-->
      <el-card class="box-card" style="flex: 1; height: 590px; overflow-y: auto;margin-left: 10px;">
        <div slot="header" class="clearfix">
          <span><strong>项目申报类别</strong></span>
          <el-button style="float: right; padding: 3px 0" type="text" @click="applicationAdd">添加分类</el-button>
        </div>
        <div v-for="(o, index) in proApplication" :key="o.id" class="text item">
          {{ index + 1 }}. {{ o.category }} ..........{{"绩效：" + o.score }}
          <el-button style="float: right; padding: 3px 0" type="text" @click="applicationDeleteById(o.id)">删除</el-button>
        </div>
      </el-card>


    </div>




  </div>
</template>

<script>
// import teacher from '@/api/adm/teacherAdmin'
import * as teacher from '@/api/adm/teacherAdmin'
import { busDeleteById, disable, disableTeacher } from '@/api/adm/teacherAdmin'
import * as admin from '@/api/super/admin'

    export default {
      data() {
        return {
          list: null, // 查询之后接口返回集合
          category: null, //学院接口
          bus: null, //教师提交材料分类
          proApplication: null //项目申报类别
        }
      },
      created() {
        this.getListCollege()
        this.getListBus()
        this.getListApplication()
      },
      methods: {
        // 查询学院信息
        getListCollege() {
          teacher.findAllCategory()
            .then(response => {
              this.category = response.data.category
              console.log("@@@@@@@@@" + this.category)
            })
        },
        // 查询教师提交材料分类
        getListBus() {
          teacher.findAllBus()
            .then(response => {
              this.bus = response.data.bus
              console.log("@@@@@@@@@" + this.bus)
            })
        },
        //项目申报类别
        getListApplication() {
          teacher.findAllApplication()
            .then(response => {
              this.proApplication = response.data.proApplication
              console.log("@@@@@@@@@" + this.proApplication)
            })
        },

        //添加学院
        categoryAdd() {
          this.$prompt('学院名称', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            inputPattern: /.+/,
            inputErrorMessage: '学院名称不能为空'
          }).then(({ value }) => {
            teacher.categoryAdd(value)
              .then(response => {
                // 处理成功响应
                this.$message({
                  type: 'success',
                  message: '提交成功'
                });
                this.getListCollege()
              })
              .catch(error => {
                // 处理错误响应
                this.$message({
                  type: 'error',
                  message: '提交失败'
                });
              });
          }).catch(() => {
            this.$message({
              type: 'info',
              message: '取消输入'
            });
          });
        },
        // 添加教师提交材料分类
        busAdd() {
          this.$prompt('材料名称', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            inputPattern: /.+/,
            inputErrorMessage: '材料不能为空'
          }).then(({ value: materialName }) => {
            this.$prompt('绩效', '提示', {
              confirmButtonText: '确定',
              cancelButtonText: '取消',
              inputPattern: /^\d+(\.\d+)?$/,
              inputErrorMessage: '绩效不能为空且必须是数字'
            }).then(({ value: performance }) => {
              teacher.busAdd(materialName, performance)
                .then(response => {
                  // 处理成功响应
                  this.$message({
                    type: 'success',
                    message: '提交成功'
                  });
                  this.getListBus()
                })
                .catch(error => {
                  // 处理错误响应
                  this.$message({
                    type: 'error',
                    message: '提交失败'
                  });
                });
            }).catch(() => {
              this.$message({
                type: 'info',
                message: '取消输入'
              });
            });
          }).catch(() => {
            this.$message({
              type: 'info',
              message: '取消输入'
            });
          });
        },
        //添加项目申报类别
        applicationAdd() {
          this.$prompt('类别名称', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            inputPattern: /.+/,
            inputErrorMessage: '类别名称不能为空'
          }).then(({ value: materialName }) => {
            this.$prompt('绩效', '提示', {
              confirmButtonText: '确定',
              cancelButtonText: '取消',
              inputPattern: /^\d+(\.\d+)?$/,
              inputErrorMessage: '绩效不能为空且必须是数字'
            }).then(({ value: performance }) => {
              teacher.applicationAdd(materialName, performance)
                .then(response => {
                  // 处理成功响应
                  this.$message({
                    type: 'success',
                    message: '提交成功'
                  });
                  this.getListApplication()
                })
                .catch(error => {
                  // 处理错误响应
                  this.$message({
                    type: 'error',
                    message: '提交失败'
                  });
                });
            }).catch(() => {
              this.$message({
                type: 'info',
                message: '取消输入'
              });
            });
          }).catch(() => {
            this.$message({
              type: 'info',
              message: '取消输入'
            });
          });
        },

        //删除学院
        categoryDeleteById(id){
          teacher.categoryDeleteById(id).then(response => {
            //删除成功
            this.$message({
              message: '删除成功',
              type: 'success'
            });
            this.getListCollege()
          })
        },
        // 删除教师提交材料分类
        busDeleteById(id){
          teacher.busDeleteById(id).then(response => {
            this.$message({
              type: 'success',
              message: '删除成功'
            });
            this.getListBus()
          })
        },
        //删除项目申报类别
        applicationDeleteById(id){
          teacher.applicationDeleteById(id).then(response => {
            this.$message({
              type: 'success',
              message: '删除成功'
            });
            this.getListApplication()
          })
        },
      }
}
</script>
<style>

.demo-table-expand label {
  width: 90px;
  color: #99a9bf;
}

.demo-table-expand .el-form-item {
  margin-right: 0;
  margin-bottom: 0;
  width: 50%;
}
.text {
  font-size: 14px;
}

.item {
  margin-bottom: 18px;
}

.clearfix:before,
.clearfix:after {
  display: table;
  content: "";
}
.clearfix:after {
  clear: both
}

.box-card {
  width: 480px;
}
</style>
